package com.losdun.product.domain.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.losdun.product.domain.BaseTreeEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author sword.ye
 * @date 2025/3/1
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TreeSelectVo implements Serializable {

    private static final long serialVersionUID = 1L;
    /** 节点ID */
    private Long id;

    /** 节点名称 */
    private String label;

    /** 节点禁用 */
    private boolean disabled = false;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelectVo> children;



    public <T extends BaseTreeEntity> TreeSelectVo(T obj) {
        this.id=obj.getId();
        this.label=obj.getName();
        this.children=obj.getChildren().stream().map(t->new TreeSelectVo((T) t)).collect(Collectors.toList());
    }

    /**
     * 是否有子节点
     * @return
     */
    public boolean hasChildren(){
       return this.children!=null && !this.children.isEmpty();
    }


}
